<?php namespace sacvoyage\storage;

require_once("Database.php");

class Storage {



	public function __construct(Gateway $gateway) {
		$this->_gateway=$gateway;
		$this->_ensureTables();
	}


	public function getDatabase($name) {
		if(!array_key_exists($name, $this->_databaseCache)) {
			$this->_databaseCache[$name]=new Database($this->_gateway, $name);
		}
		return $this->_databaseCache[$name];
	}

	private $_gateway;
	private $_databaseCache=array();

	private function _ensureTables() {
	
		$this->_gateway->query('CREATE TABLE IF NOT EXISTS sacvoyage_databases (
	name TEXT NOT NULL,
	table_prefix TEXT NOT NULL,
	UNIQUE(name(100)),
	UNIQUE(table_prefix(100)),
	INDEX(name(100))
) DEFAULT CHARSET=utf8 COLLATE=utf8_bin');

	}
	
	
	

}








?>
